package service

import (
	"go_web/config"
	"go_web/dao"
	"go_web/models"
)

func FindPostPigeonhole() (models.PigeonholeRes, error) {
	//查询所有的文字，进行月份的整理
	//查询所有的分类

	allPosts, _ := dao.GetAllPosts()

	pigeonholeMap := make(map[string][]models.Post)

	for _, post := range allPosts {
		creat_at := post.CreateAt
		month := creat_at.Format("2006-1")
		pigeonholeMap[month] = append(pigeonholeMap[month], post)
	}

	categorys, _ := dao.GetAllCategory()

	return models.PigeonholeRes{
		Viewer:       config.Cfg.Viewer,
		SystemConfig: config.Cfg.System,
		Categorys:    categorys,
		Lines:        pigeonholeMap,
	}, nil

}
